const fs = require('fs');
const express = require('express');
const morgan = require('morgan');
// 创建app对象
const app = express();
// 应⽤第三⽅中间件
// 创建⼀个WriteStream，⽤于将⽇志数据写⼊⽂件
const writeStream = fs.createWriteStream('./logs/access.log', { flags: 'a' });
// 使⽤morgan将请求⽇志记录到指定⽂件中
app.use(morgan('combined', { stream: writeStream }));
// 编写中间件
app.post('/login', (req, res, next) => {
res.end('登录成功, 欢迎回来~');
});
// 启动服务器
app.listen(9000, () => {
console.log('express服务器启动成功~');
});